//
//  CalculatorView.swift
//  Calculator
//
//  Created by YJH on 2025/5/3.
//

import UIKit

class CalculatorView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupViews() {
        let mathOperator = ["=",".","0","%","+","3","2","1","-","6","5","4","x","9","8","7","/","AC","Del"]
        var yOffset: CGFloat = 800
        var xOffset: CGFloat = 300
        let buttonSize: CGFloat = 50 // 按钮的大小
        // 使用 RGB 值创建颜色
        let customColor = UIColor(red: 178/255.0, green: 187/255.0, blue: 190/255.0, alpha: 1.0)
        
        for index in 0..<mathOperator.count {
            if index % 4 == 0 {
                yOffset -= buttonSize + 20
                xOffset = 300
            } else{
                xOffset -= buttonSize + 20
                
            }
            let button = UIButton(type: .system)

            button.setTitle(mathOperator[index], for: .normal)
            button.frame = CGRect(x: xOffset, y: yOffset, width: buttonSize, height: buttonSize)

            // 设置按钮为圆形样式
            button.layer.cornerRadius = buttonSize / 2
            button.layer.masksToBounds = true

            button.setTitleColor(.black, for: .normal) // 设置字体颜色为黑色

            button.backgroundColor = customColor
            button.layer.borderColor = UIColor.lightGray.cgColor
            button.layer.borderWidth = 1

            addSubview(button)
        }
    }
    
}
